<?php
/**
 * Created by PhpStorm.
 * User: Egg
 * Date: 2018/3/23
 * Time: 16:00
 */

namespace Admin\Model;


class UserListLogic
{
    public function getUserListByName($name)
    {
        $map['nickname'] = array('like', '%' . $name . '%');
        $result = D('admin')
            ->alias('a')
            ->join('left join think_auth_group_access as ga on a.id = ga.uid')
            ->join('left join think_auth_group as g on g.id = ga.group_id')
            ->field(array(
                'a.id' => 'id',
                'nickname' => 'name',
                'g.title' => 'department',
                'last_login_time',
                'last_login_ip'
            ))
            ->page(I('get.page'), 15)
            ->where($map)
            ->select();
        $data['users'] = $result;
        $data['max_page'] = ceil(D('admin')->where($map)->count() / 15);
        \Common\Common\print_json_data(200, $data, '查询成功');
        exit;
    }

    public function getUserListByGid($gid)
    {
        $where['g.id'] = array('like', $gid . '%');
        $result = D('group')
            ->alias('g')
            ->join('left join think_auth_group_access as ga on g.id = ga.group_id')
            ->join('left join sys_users as a on a.id = ga.uid')
            ->field(array(
                'a.id' => 'id',
                'nickname' => 'name',
                'g.title' => 'department',
                'last_login_time',
                'last_login_ip'
            ))
            ->page(I('get.page'), 15)
            ->where($where)
            ->select();
        $data['users'] = $result;
        $data['max_page'] = ceil(D('group')
                ->alias('g')
                ->join('left join think_auth_group_access as ga on g.id = ga.group_id')
                ->join('left join sys_users as a on a.id = ga.uid')
                ->where($where)
                ->count() / 15);
        \Common\Common\print_json_data(200, $data, '查询成功');
        exit;
    }
}